package com.tg.app.helper;

import android.content.Context;
import android.content.DialogInterface;

import com.appbase.custom.constant.SensitivityConstants;
import com.tg.app.widget.BottomRadioButtonSheetListDialog;
import com.tg.appcommon.android.TGLog;

import java.util.ArrayList;
import java.util.List;

public class BottomRadioSheetDialogHelper {

    private static final String TAG = "BottomRadioSheetDialogHelper";

    /**
     * 碰撞感应设置弹窗
     */
    public static void showCollisionSensingSettings(Context context, int sensitivityLevel,
                                                    DialogInterface.OnDismissListener onDismissListener, BottomRadioButtonSheetListDialog.BottomSheetClickListener onClickListener,
                                                    String title) {

        TGLog.i(TAG, "[showCollisionSensingSettings] current sensitivityLevel = " + sensitivityLevel);

        final BottomRadioButtonSheetListDialog dialog = new BottomRadioButtonSheetListDialog(context);
        dialog.setTitle(title);

        final BottomRadioButtonSheetListDialog.BottomSheetItem item1 =
                new BottomRadioButtonSheetListDialog.BottomSheetItem(SensitivityConstants.CAR_SENSITIVITY_LEVEL_HIGH,
                        context.getString(com.appbase.custom.R.string.settings_sensitivity_level_high));

        final BottomRadioButtonSheetListDialog.BottomSheetItem item2 =
                new BottomRadioButtonSheetListDialog.BottomSheetItem(SensitivityConstants.CAR_SENSITIVITY_LEVEL_MID,
                        context.getString(com.appbase.custom.R.string.settings_sensitivity_level_mid));

        final BottomRadioButtonSheetListDialog.BottomSheetItem item3 =
                new BottomRadioButtonSheetListDialog.BottomSheetItem(SensitivityConstants.CAR_SENSITIVITY_LEVEL_LOW,
                        context.getString(com.appbase.custom.R.string.settings_sensitivity_level_low));

        final BottomRadioButtonSheetListDialog.BottomSheetItem item4 =
                new BottomRadioButtonSheetListDialog.BottomSheetItem(SensitivityConstants.CAR_SENSITIVITY_LEVEL_CLOSE,
                        context.getString(com.appbase.custom.R.string.settings_sensitivity_level_close));

        int selectedIndex = -1;

        if (sensitivityLevel >= 0) {
            switch (sensitivityLevel) {
                case SensitivityConstants.CAR_SENSITIVITY_LEVEL_HIGH:
                    selectedIndex = 0;
                    break;
                case SensitivityConstants.CAR_SENSITIVITY_LEVEL_MID:
                    selectedIndex = 1;
                    break;
                case SensitivityConstants.CAR_SENSITIVITY_LEVEL_LOW:
                    selectedIndex = 2;
                    break;
                case SensitivityConstants.CAR_SENSITIVITY_LEVEL_CLOSE:
                    selectedIndex = 3;
                    break;
            }
        }

        TGLog.i(TAG, "[showCollisionSensingSettings] set selectedIndex = " + selectedIndex);

        final List<BottomRadioButtonSheetListDialog.BottomSheetItem> list = new ArrayList<>();
        list.add(item1);
        list.add(item2);
        list.add(item3);
        list.add(item4);

        dialog.setData(list);
        dialog.setSelectedIndex(selectedIndex);
        dialog.setCanceledOnTouchOutside(true);

        dialog.setOnDismissListener(dialog1 -> {
            TGLog.i(TAG, "[showCollisionSensingSettings] on dismiss !");
            if (onDismissListener != null) onDismissListener.onDismiss(dialog1);
        });

        dialog.setClickListener((action, text) -> {
            TGLog.i(TAG, "[showCollisionSensingSettings] onClick action = " + action);
            if (onClickListener != null) {
                onClickListener.onClick(action, text);
            }
        });

        dialog.show();
    }
}
